<script>
export default {
  name: 'FormItemDispatcher',
  props: {
    setting: {
      type: Object,
      default () {
        return {}
      }
    },
    editable: {
      type: Boolean,
      default: false
    },
    markSelect: {
      type: Boolean,
      default: true
    },
    selected: {
      type: Boolean,
      default: false
    }
  },
  functional: true,
  render (h, context) {
    const { setting, editable, selected, markSelect } = context.props
    const { type } = setting
    let extra = {}
    let component
    switch (type) {
      case 'input':
        component = require('./widgets/input').default
        break
      case 'textarea':
        component = require('./widgets/textarea').default
        break
      case 'select':
        component = require('./widgets/select').default
        break
      case 'grid':
        component = require('./widgets/grid').default
        break
      case 'button':
        component = require('./widgets/button').default
        break
      case 'chart':
        component = require('./widgets/chart').default
        break
    }
    return h(component, { props: { setting, editable, selected, markSelect, ...extra } })
  }
}
</script>
